<?php
session_set_cookie_params(10);
session_start();
$post_student_id = $_POST['post_student_id'];
$post_password = $_POST['post_password'];

////mysql数据准备-------------------------------------------------------------------------------------------------
//create database big_data_221;
//use big_data_221;
//create table student(
//    stu_id            int           not null,
//stu_name          varchar(255)  not null,
//stu_password      int           not null,
//stu_phone_num     bigint        not null,
//stu_age           int           default null,
//stu_sex           varchar(4)    not null,
//stu_room_num      int           default null,
//stu_identity_num  bigint        default null);
//
//# DCL创建用户
//create user 'class_page'@'%' identified by '1';
//flush privileges;
//
//# DCL修改权限
//GRANT SELECT, INSERT, UPDATE, DELETE ON big_data_221.* TO 'class_page'@'%';
//flush privileges;
//
//# 测试数据
//use big_data_221;
//insert into student values(123456789,'zhangSan',123456,12345678987,19,'男',101,510623197903208013);
//-------------------------------------------------------------------------------------------------

//数据库查询
$db_host = 'localhost:3306';
$db_name = 'big_data_221';
$db_user = 'class_page';
$db_pwd = '1';
$table_name = 'student';
$col_name = 'stu_password';
$real_stu_password = 0;

//创建数据库查询
$mysqli = new mysqli($db_host, $db_user, $db_pwd, $db_name);
//预处理SQL语句
$sql = 'select ' . $col_name . ' from ' . $table_name . ' where stu_id = ' . $post_student_id;
// 执行查询
$result = $mysqli->query($sql);

if ($result->num_rows == 0){
    header('Location:user_register.html');
}else{
    // 处理每一行数据
    while ($row = $result->fetch_assoc()) {
        $real_stu_password = $row['stu_password'];
    }
    if ($post_password == $real_stu_password) {
        $_SESSION['is_login'] = true;
        $_SESSION['msg_true'] = '恭喜登录成功';
        header('Location:user_login.php');
    } else {
        $_SESSION['is_login'] = false;
        $_SESSION['msg_false'] = '用户名或密码错误，请重试';
        header('Location:user_login.php');
    }
}
// 关闭连接
$mysqli->close();
session_destroy();
?>
